﻿using Appliaction.Dto.DB;
using Appliaction.IAppServices.DB;
using AutoMapper;
using Domain.Entitys.DB;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers.DB
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class Db_MeasureController : ControllerBase
    {
        private readonly IMapper mapper;
        private readonly IDb_MeasureService db_MeasureService;

        public Db_MeasureController(IMapper mapper,IDb_MeasureService db_MeasureService)
        {
            this.mapper = mapper;
            this.db_MeasureService = db_MeasureService;
        }

        /// <summary>
        /// 查询总条数
        /// </summary>
        /// <param name="Measure_code">编码</param>
        /// <param name="Measure_name">昵称</param>
        /// <returns></returns>
        [HttpGet]
        public int Db_MeasureCount(string? Measure_code, string? Measure_name)
        {
            return db_MeasureService.Db_MeasureCount(Measure_code, Measure_name);
        }

        /// <summary>
        /// 分页查询、条件查询
        /// </summary>
        /// <param name="Measure_code">编码</param>
        /// <param name="Measure_name">昵称</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="pageSize">查几条</param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult SelectDb_MeasureFYWHERE(string? Measure_code, string? Measure_name, int currentPage, int pageSize)
        {
            return new JsonResult(db_MeasureService.SelectDb_MeasureFYWHERE(Measure_code, Measure_name, currentPage, pageSize));
        }

        /// <summary>
        /// 逻辑删除计量单位
        /// </summary>
        /// <param name="db_MeasureDelete"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Db_MeasureDelete(Db_MeasureDeleteDto db_MeasureDelete)
        {
            return new JsonResult(await db_MeasureService.Db_MeasureDelete(db_MeasureDelete));
        }

        /// <summary>
        /// 添加计量单位
        /// </summary>
        /// <param name="db_MeasureAddDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> Db_MeasureAdd(Db_MeasureAddDto db_MeasureAddDto)
        {
            return new JsonResult(await db_MeasureService.Db_MeasureAdd(db_MeasureAddDto));
        }

        /// <summary>
        /// 添加计量单位
        /// </summary>
        /// <param name="db_MeasureUpdateDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> Db_MeasureUpdate(Db_MeasureUpdateDto db_MeasureUpdateDto)
        {
            return new JsonResult(await db_MeasureService.Db_MeasureUpdate(db_MeasureUpdateDto));
        }
    }
}
